<?
    // Initialize the session.
    session_start();
    require_once("../inc/checkAdminPagePermissions.php");
    require_once("../inc/config.inc.php");
    require_once('../conexion.php');
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">

<html>
<head>
    <title><? echo _SITE_NAME; ?> :: Panel Administrativo :: Inicio</title>
    <meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
    <link href="../css/main.css" type=text/css rel=stylesheet>
	<script>
		function cerrar()
{
if (confirm("Desea salir sin aplicar los cambios ?"))
   {
     parent.location="../index.php";
   }
}
	function valcorreo(valor) {
if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/.test(valor)){
return (true)
} else {
return (false);
}
}
function isPhoneNumber(s) 
{

     // Check for correct phone number
     rePhoneNumber = new RegExp( /^\d{4}-\d{7}$/);
     if (!rePhoneNumber.test(s)) {
             return false;
     }

return true;
}

function validar(forma)
{
if (forma.vieja.value=="")
{
 alert("Por favor introduzca clave anterior");
 forma.vieja.focus();
 return false;
}
if (forma.vieja.value!=forma.clavevieja.value)
{
 alert("Clave anterior no concuerda");
 forma.vieja.focus();
 return false;
}


if (forma.nueva.value=="")
{
 alert("Por favor introduzca nueva clave");
 forma.nueva.focus();
 return false;
}
if (forma.nueva2.value=="")
{
 alert("Por favor confirme nueva clave");
 forma.nueva2.focus();
 return false;
}
if (forma.nueva2.value!=forma.nueva.value)
{
 alert("Nueva clave y confirmacion no son iguales");
 forma.nueva.focus();
 return false;
}

return true;
}

	</script>
</head>


<!-- BEGIN MAIN CONTENT ARE -->
<body style="background: #ffffff;">

<div align="left">
  <h4>Mantenimiento -> Cambiar Clave</h4>
</div>
<?php

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $clave=$_POST["nueva"];
	$cadena="UPDATE admins set password='$clave' WHERE id=$_SESSION[adm_user_id] ";
	mysql_query($cadena);	
	 $cadena="INSERT INTO auditoria (idusuario, accion, ip) VALUES ($_SESSION[adm_user_id],'Usuario cambio su clave','$_SERVER[REMOTE_ADDR]')";
	mysql_query($cadena);
	echo "<script>alert('Clave Actualizada');parent.location='../index.php';</script>";
	
     
   }


?>
<form action="cambiarclave.php" method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="return validar(this)">
  <table width="95%" border="0" align="center" cellpadding="1" cellspacing="1">
  <tr>
  <td colspan="2" align="left">(*) Campos Obligatorios  </td>
  </tr>
    <tr >
      <td colspan="2" ><hr size="1" /></td>
    </tr>
    <tr  >
      <td width="18%" ><div align="left"><strong>Clave Anterior:</strong></div></td>
      <td width="85%" ><div align="left">
        <input name="vieja" type="password" id="vieja" size="50" maxlength="250" title="Clave anterior" >
      (*)</div></td>
    </tr>
	<tr  >
      <td width="18%" ><div align="left"><strong>Nueva Clave:</strong></div></td>
      <td width="85%" ><div align="left">
        <input name="nueva" type="password" id="nueva" size="50" maxlength="250"  title="Nueva clave" >
      (*)</div></td>
    </tr>
	<tr  >
      <td width="18%" ><div align="left"><strong>Confirmar nueva clave:</strong></div></td>
      <td width="85%" ><div align="left">
        <input name="nueva2" type="password" id="nueva2" title="Confirmacion nueva clave" value="" size="50">
      (*)</div></td>
    </tr>
	 <input name="clavevieja" type="hidden" id="clavevieja"  value="<?=$_SESSION['clave']; ?>">
<!--tr  >
      <td width="15%" ><div align="left"><strong>Sector Economico:</strong></div></td>
      <td width="85%" ><div align="left">
        <select name="sector" id="sector">
          <option value="Sector 1">Sector 1</option>
		</select>
      </div></td>
    </tr-->
    <tr >
      <td colspan="3" ><hr size="1" /></td>
    </tr>
    <tr >
      <td  colspan="3" align="center" ><input name="Submit" type="submit"  value="Aceptar Datos" />
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input name="Submit3" type="button"  onClick="cerrar()" value="Menu Principal" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
 
</form>
</body>
</html>
